package com.happyfamily.springboot.crowdsourcingplatform.service.guo.impl;

import com.happyfamily.springboot.crowdsourcingplatform.dao.guo.FrontNeedDao;
import com.happyfamily.springboot.crowdsourcingplatform.dao.guo.ServiceDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.*;
import com.happyfamily.springboot.crowdsourcingplatform.service.guo.ServiceProvidersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class ServiceProvidersServiceImpl implements ServiceProvidersService
{

	@Autowired(required = false)
	ServiceDao serviceDao;

	@Override
	public List<Orders> getTenderList(String account)
	{
		SysUser user=serviceDao.getUser(account);
		List<Alliance> list =serviceDao.getAllianceList2(user.getUid());
		ArrayList<Tender> list3=new ArrayList<>();
		if (list.size()>0){
			for (int i = 0; i <list.size() ; i++)
			{
				List<Tender> list1=serviceDao.getOneTender(Long.valueOf(list.get(i).getAid()),"联盟投标");
				System.out.println("当前联盟的长度"+list1.size());
				if (list1.size()>0){
					for (int j = 0; j <list1.size() ; j++)
					{
						list3.add(list1.get(j));
					}
				}
			}

		}

		List<Tender> list2=serviceDao.getOneTender(Long.valueOf(user.getUid()),"个人投标");
		if (list2.size()>0){
			for (int k = 0; k <list2.size() ; k++)
			{
				list3.add(list2.get(k));
			}
		}
		ArrayList<Orders> ordersList=new ArrayList<>();
		for (int i = 0; i <list3.size() ; i++)
		{
			Orders orders=serviceDao.getOrder(list3.get(i).getNeedid());
			ordersList.add(orders);
		}

		return ordersList;
	}

	@Override
	public List<OrderForm> getOrderForm(Long orderid)
	{
		return serviceDao.getOrderForm(orderid);
	}
}
